﻿using System;
using System.Collections.Specialized;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Text;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.IO;
using System.Xml;
using System.Web.Security;

using Maticsoft.BLL;
using Maticsoft.DBUtility;

using Utils;

/// <summary>
///BasePage 的摘要说明
/// </summary>
public class BasePage : System.Web.UI.Page
{
    Maticsoft.Model.System  _assystem = null;
    private NameValueCollection _assytemarr = null;
    private Maticsoft.Model.UserInfo _asuser = null;
    private NameValueCollection _ASUserArr = null;
    private Maticsoft.Model.Category _city = null;
    private DataTable _citylist = new DataTable();
    private Maticsoft.Model.Team _currentteam = null;
    private bool? _ismanager = null;
    public const string admin = "admin";
    private Maticsoft.Model.UserInfo asuser = null;
    public const string help = "help";
    private bool ispartner = false;
    public const string market = "market";
    public const string order = "order";
    public const string PassWordKey = "@4!@#$%@";
    public const string team = "team";

    // Methods
    public bool CheckUserAuth(string authval)
    {
        bool flag = false;
        if (this.ASUser != null)
        {
            if (this.ASUser.Auth.IndexOf("{" + authval + "}") >= 0)
            {
                flag = true;
            }
            if (this.IsSupper)
            {
                flag = true;
            }
        }
        return flag;
    }

    public void ClearCookie()
    {
        HttpCookie cookie = new HttpCookie("Tuan");
        cookie.Expires = DateTime.Now.AddDays(-1.0);
        HttpContext.Current.Response.AppendCookie(cookie);
    }

    public string Css()
    {
        if (this.Page.Request.Url.AbsoluteUri.ToLower().Contains("webpage"))
        {
            return (this.WebRoot + "upfile/Manager/css/index.css");
        }
        if ((this.ASSystem != null) && (this.ASSystem.skintheme != string.Empty))
        {
            return (this.WebRoot + "upfile/theme/" + this.ASSystem.skintheme + "/css/index.css");
        }
        return (this.WebRoot + "upfile/css/index.css");
    }

    private string GetArgs(string strArgName, string strUrl)
    {
        string str = "";
        string[] strArray = strUrl.Split(new char[] { '&' });
        int length = strArray.Length;
        for (int i = 0; i < length; i++)
        {
            int index = strArray[i].ToString().IndexOf("=");
            if ((index != -1) && (strArray[i].ToString().Substring(0, index) == strArgName))
            {
                str = strArray[i].ToString().Substring(index + 1);
            }
        }
        return str;
    }

    public string GetCookie(string cookiename)
    {
        HttpCookie cookie = HttpContext.Current.Request.Cookies["Tuan"];
        string text = string.Empty;
        if (cookie != null)
        {
            try
            {
                text = cookie.Values[cookiename].ToString();
                string str2 = DESEncrypt.Decrypt(text, Getkey());
                text = DESEncrypt.Decrypt(text, Getkey());
            }
            catch
            {
            }
        }
        return text;
    }

    public string GetCount(string strCount, string strWhere, string TableName)
    {
        string str = "0";
        StringBuilder builder = new StringBuilder();
        builder.Append("select " + strCount + " as num ");
        builder.Append(" FROM [" + TableName + "] ");
        if (strWhere.Trim() != "")
        {
            builder.Append(" where " + strWhere);
        }
        DataSet set = DbHelperSQL.Query(builder.ToString());
        if (set.Tables.Count <= 0)
        {
            return str;
        }
        if (set.Tables[0].Rows.Count <= 0)
        {
            return str;
        }
        if ((set.Tables[0].Rows[0]["num"] == null) || (set.Tables[0].Rows[0]["num"].ToString() == ""))
        {
            return "0";
        }
        return set.Tables[0].Rows[0]["num"].ToString();
    }

    public string GetDecryptValue(string value)
    {
        if (value.Length == 0)
        {
            return string.Empty;
        }
        try
        {
            value = Convert.ToInt32(DESEncrypt.Decrypt(value, Getkey())).ToString();
        }
        catch
        {
            value = string.Empty;
        }
        return value;
    }

    public string Getfile()
    {
        StreamWriter writer;
        string randomString = "";
        if (File.Exists(base.Server.MapPath("~/loginkey.config")))
        {
            try
            {
                XmlDocument document = new XmlDocument();
                document.Load(base.Server.MapPath("~/loginkey.config"));
                XmlNode node = document.SelectSingleNode("//appSettings/add[@key='login']");
                if (node == null)
                {
                    return randomString;
                }
                randomString = node.Attributes["value"].Value;
                if (randomString.Length != 8)
                {
                    randomString = Utils.Helper.GetRandomString(8);
                    node.Attributes["value"].Value = randomString;
                    document.Save(base.Server.MapPath("~/loginkey.config"));
                }
            }
            catch (Exception)
            {
                File.Create(base.Server.MapPath("~/loginkey.config")).Close();
                randomString = Utils.Helper.GetRandomString(8);
                writer = new StreamWriter(base.Server.MapPath("~/loginkey.config"), false, Encoding.UTF8);
                try
                {
                    writer.Write("<?xml version='1.0'?>");
                    writer.Write("<appSettings>");
                    writer.Write("<add key='login' value='" + randomString + "' />");
                    writer.Write("</appSettings>");
                    writer.Close();
                }
                catch
                {
                }
            }
            return randomString;
        }
        File.Create(base.Server.MapPath("~/loginkey.config")).Close();
        randomString = Utils.Helper.GetRandomString(8);
        writer = new StreamWriter(base.Server.MapPath("~/loginkey.config"), false, Encoding.UTF8);
        try
        {
            writer.Write("<?xml version='1.0'?>");
            writer.Write("<appSettings>");
            writer.Write("<add key='login' value='" + randomString + "' />");
            writer.Write("</appSettings>");
            writer.Close();
        }
        catch
        {
        }
        return randomString;
    }

    public static string Getkey()
    {
        BasePage page = new BasePage();
        return page.Getlogin();
    }

    public string Getlogin()
    {
        string cacheKey = "login";
        object cache = LTP.Common.DataCache.GetCache(cacheKey);
        if (cache == null)
        {
            try
            {
                cache = this.Getfile();
                if ((cache != null) || (cache != ""))
                {
                   LTP.Common.DataCache.SetCache(cacheKey, cache, DateTime.Now.AddDays(1.0), TimeSpan.Zero);
                }
            }
            catch
            {
            }
        }
        return cache.ToString();
    }

    private string getMd5Hash(string input)
    {
        int num;
        MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
        char[] chArray = input.ToCharArray();
        byte[] buffer = new byte[chArray.Length];
        for (num = 0; num < chArray.Length; num++)
        {
            buffer[num] = (byte)chArray[num];
        }
        byte[] buffer2 = provider.ComputeHash(buffer);
        StringBuilder builder = new StringBuilder();
        for (num = 0; num < buffer2.Length; num++)
        {
            builder.Append(buffer2[num].ToString("x2"));
        }
        return builder.ToString();
    }

    public string GetMoney(object price)
    {
        string str = string.Empty;
        if (price == null)
        {
            return str;
        }
        Regex regex = new Regex(@"^(\d+)$|^(\d+.[1-9])0$|^(\d+).00$");
        Match match = regex.Match(price.ToString());
        if (match.Success)
        {
            return regex.Replace(match.Value, "$1$2$3");
        }
        return price.ToString();
    }

    public bool GetRedirect()
    {
        if (!File.Exists(base.Server.MapPath("~/db/") + "install.ok"))
        {
            base.Response.Redirect("install.aspx");
            base.Response.End();
            return false;
        }
        return true;
    }

    public string GetRefer()
    {
        string cookieValue = CookieHelper.GetCookieValue("refer");
        if (cookieValue == string.Empty)
        {
            cookieValue = "~/Index.aspx";
        }
        CookieHelper.ClearCookie("refer");
        return cookieValue;
    }

    protected TeamState GetState( Maticsoft.Model.Team t)
    {
       
        if (t.End_time < DateTime.Now)
        {
            if (t.Now_number < t.Min_number)
            {
                return TeamState.fail;
            }
            return TeamState.successtimeover;
        }
        if (DateTime.Now <= t.End_time)
        {
            if (((t.Now_number >= t.Max_number) && (t.Max_number != 0)) && (t.Now_number != 0))
            {
                return TeamState.successnobuy;
            }
            if (t.Now_number < t.Min_number)
            {
                if (((t.Now_number >= t.Max_number) && (t.Max_number != 0)) && (t.Now_number != 0))
                {
                    return TeamState.successnobuy;
                }
                if (t.Now_number >= t.Min_number)
                {
                    return TeamState.successbuy;
                }
                return TeamState.begin;
            }
            if (t.Now_number < t.Min_number)
            {
                return TeamState.begin;
            }
            if ((t.Max_number == 0) && (t.Now_number == 0))
            {
                return TeamState.begin;
            }
            return TeamState.successbuy;
        }
        return TeamState.none;
    }

    protected TeamState GetState(DataRow team_row)
    {
        DataRowObject obj2 = new DataRowObject(team_row);
        if (obj2.ToDateTime("End_time") < DateTime.Now)
        {
            if (obj2.ToInt("Now_number") < obj2.ToInt("Min_number"))
            {
                return TeamState.fail;
            }
            return TeamState.successtimeover;
        }
        if (DateTime.Now <= obj2.ToDateTime("End_time"))
        {
            if (((obj2.ToInt("Now_number") >= obj2.ToInt("Max_number")) && (obj2.ToInt("Max_number") != 0)) && (obj2.ToInt("Now_number") != 0))
            {
                return TeamState.successnobuy;
            }
            if (obj2.ToInt("Now_number") < obj2.ToInt("Min_number"))
            {
                if (((obj2.ToInt("Now_number") >= obj2.ToInt("Max_number")) && (obj2.ToInt("Max_number") != 0)) && (obj2.ToInt("Now_number") != 0))
                {
                    return TeamState.successnobuy;
                }
                if (obj2.ToInt("Now_number") >= obj2.ToInt("Min_number"))
                {
                    return TeamState.successbuy;
                }
                return TeamState.begin;
            }
            if (obj2.ToInt("Now_number") < obj2.ToInt("Min_number"))
            {
                return TeamState.begin;
            }
            if ((obj2.ToInt("Max_number") == 0) && (obj2.ToInt("Now_number") == 0))
            {
                return TeamState.begin;
            }
            return TeamState.successbuy;
        }
        return TeamState.none;
    }

    public string GetTeamStateName(TeamState state)
    {
        string str = string.Empty;
        switch (state)
        {
            case TeamState.none:
                return "未开始";

            case TeamState.begin:
                return "正在进行";

            case TeamState.successbuy:
                return "成功可继续";

            case (TeamState.successbuy | TeamState.begin):
            case (TeamState.successnobuy | TeamState.begin):
            case (TeamState.successnobuy | TeamState.successbuy):
            case (TeamState.successnobuy | TeamState.successbuy | TeamState.begin):
                return str;

            case TeamState.successnobuy:
                return "成功已卖光";

            case TeamState.successtimeover:
                return "成功已过期";

            case TeamState.fail:
                return "失败";
        }
        return str;
    }

    public string ImagePath()
    {
        string str = this.WebRoot + "upfile/css/i/";
        if (this.Page.Request.Url.AbsoluteUri.ToLower().Contains("webpage"))
        {
            return (this.WebRoot + "upfile/Manager/css/i/");
        }
        if ((this.ASSystem != null) && (this.ASSystem.skintheme != string.Empty))
        {
            return (this.WebRoot + "upfile/theme/" + this.ASSystem.skintheme + "/css/i/");
        }
        return (this.WebRoot + "upfile/css/i/");
    }

    public void IncludeEditorJS()
    {
        if (this.Page.Header != null)
        {
            this.Page.Header.Controls.Add(new LiteralControl("<script src=\"" + this.WebRoot + "upfile/js/xheditor/xheditor-zh-cn.min.js\"></script>\r\n"));
        }
    }

    public bool IsInRole(string userrole, string role)
    {
        bool flag = false;
        if ((userrole != string.Empty) && (userrole.IndexOf("{" + role + "}") >= 0))
        {
            flag = true;
        }
        return flag;
    }

    public bool IsManagerByDecryptValue(string value)
    {
        value = this.GetDecryptValue(value);
        return (value.Length > 0);
    }

    public bool IsUse()
    {
        Maticsoft.Model.UserInfo model = new Maticsoft.Model.UserInfo();
        NameValueCollection values = new NameValueCollection();
       Maticsoft.BLL.UserInfo info2 = new Maticsoft.BLL.UserInfo();
        Maticsoft.Model.System system = new Maticsoft.Model.System();
        system = new Maticsoft.BLL.System().GetModel(1);
        if (((system != null) && (system.Enablesohulogin == 1)) && ((!this.Page.User.Identity.IsAuthenticated || (this.Page.User.Identity.Name == "")) && (((base.Request.QueryString["passport"] != null) && (base.Request.QueryString["time"] != null)) && (base.Request.QueryString["sign"] != null))))
        {
            values = HttpUtility.ParseQueryString(base.Request.Url.Query, Encoding.GetEncoding("gb2312"));
            TimeSpan span = (TimeSpan)(Helper.GetWindowsTime(values["time"]) - DateTime.Now);
            if (Math.Abs(span.Days) < 1)
            {
                string str = Helper.MD5(values["passport"] + "|" + values["nick"] + "|" + Helper.GetWindowsTime(values["time"]).ToString("yyyy-MM-dd HH:mm:ss") + "|" + system.Sohuloginkey);
                if (base.Request["sign"] == str)
                {
                    model = info2.GetUserOrEmail(base.Request["passport"]);
                    if (model != null)
                    {
                        FormsAuthentication.SetAuthCookie(model.Username, false);
                    }
                    else
                    {
                        model = new Maticsoft.Model.UserInfo();
                        model.Username = values["passport"];
                        model.Email = values["passport"];
                        model.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(Helper.GetRandomString(8) + "@4!@#$%@", "md5");
                        model.Create_time = DateTime.Now;
                        model.Enable = "Y";
                        model.IP_Address = CookieHelper.GetCookieValue("gourl");
                        model.Fromdomain = CookieHelper.GetCookieValue("fromdomain");
                        info2.Add(model);
                        FormsAuthentication.SetAuthCookie(model.Username, false);
                    }
                    return true;
                }
            }
        }
        return false;
    }

    public void NeedPartner()
    {
        if (!this.IsPartner)
        {
            HttpContext.Current.Response.Redirect("~/biz/login.aspx");
            HttpContext.Current.Response.End();
        }
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        base.Response.AddHeader("P3P", "CP=CAO PSA OUR");
        this.PageInit();
    }

    public virtual void PageInit()
    {
        if (this.Page.Header != null)
        {
            string name = "全部";
            if (this.CurrentCity != null)
            {
                name = this.CurrentCity.Name;
            }
            if (this.ASSystem.Title == string.Empty)
            {
                this.Page.Header.Title = this.ASSystem.sitetitle;
            }
            else
            {
                this.Page.Header.Title = this.ASSystem.Title;
            }
            if (this.ASSystem.KeyWord == string.Empty)
            {
                this.Page.Header.Controls.Add(new LiteralControl("<meta name=\"keywords\" content=\"" + this.ASSystem.sitetitle + ", " + name + ", " + name + this.ASSystem.sitename + "，" + name + "购物，" + name + "团购，" + name + "打折，团购，打折，精品消费，购物指南，消费指南\" />\r\n"));
            }
            else
            {
                this.Page.Header.Controls.Add(new LiteralControl("<meta name=\"keywords\" content=\"" + this.ASSystem.KeyWord + "\" />\r\n"));
            }
            if (this.ASSystem.Description != string.Empty)
            {
                this.Page.Header.Controls.Add(new LiteralControl("<meta name=\"description\" content=\"" + this.ASSystem.Description + "\" />\r\n"));
            }
            this.Page.Header.Controls.Add(new LiteralControl("<script type='text/javascript' src='" + this.WebRoot + "upfile/js/index.js'></script>\r\n"));
            string cookieValue = CookieHelper.GetCookieValue("totw");
            if ((cookieValue != string.Empty) && (cookieValue == "zh_tw"))
            {
                this.Page.Header.Controls.Add(new LiteralControl("<script>totw=true;</script>\r\n"));
                this.Page.Header.Controls.Add(new LiteralControl("<script src='" + this.WebRoot + "upfile/js/zhtotw.js'></script>\r\n"));
            }
            else
            {
                this.Page.Header.Controls.Add(new LiteralControl("<script>totw=false;</script>\r\n"));
            }
            this.Page.Header.Controls.Add(new LiteralControl("<script>jQuery(document).ready(function () {jQuery(document).pngFix();}); </script>\r\n"));
            this.Page.Header.Controls.Add(new LiteralControl("<link rel=\"icon\" href=\"/upfile/icon/favicon.ico\" mce_href=\"/upfile/icon/favicon.ico\" type=\"image/x-icon\">"));
            this.Page.Header.Controls.Add(new LiteralControl("<link rel=\"stylesheet\" href=\"" + this.Css() + "\" type=\"text/css\" media=\"screen\" charset=\"utf-8\" />\r\n"));
            int id = 0;
            if (this.AsUser != null)
            {
                id = this.AsUser.Id;
            }
            this.Page.Header.Controls.Add(new LiteralControl(string.Concat(new object[] { "<script>webroot='", this.WebRoot, "';LOGINUID='", id, "';</script>\r\n" })));
        }
    }

    public string PageInitStr()
    {
        StringBuilder builder = new StringBuilder();
        builder.Append("<script src='" + this.WebRoot + "upfile/js/index.js'></script>\r\n");
        builder.Append("<link rel=\"stylesheet\" href=\"" + this.WebRoot + "upfile/css/index.css\" type=\"text/css\" media=\"screen\" charset=\"utf-8\" />\r\n");
        int id = 0;
        if (this.AsUser != null)
        {
            id = this.AsUser.Id;
        }
        builder.Append(string.Concat(new object[] { "<script>webroot='", this.WebRoot, "';LOGINUID='", id, "';</script>\r\n" }));
        return builder.ToString();
    }

    public bool SendMail(List<string> toMails, string subject, string body, out string error)
    {
        bool sendOK = false;
        error = string.Empty;
        if (this.ASSystem != null)
        {
            if ((((this.ASSystem.mailfrom == string.Empty) || (this.ASSystem.mailhost == string.Empty)) || (this.ASSystem.mailpass == string.Empty)) || (this.ASSystem.mailuser == string.Empty))
            {
                return sendOK;
            }
            if (((toMails.Count == 0) || (subject == string.Empty)) || (body == string.Empty))
            {
                return sendOK;
            }
            int @int = Helper.GetInt(this.ASSystem.mailport, 0);
            if (@int == 0)
            {
                @int = 0x19;
            }
            error = MailHelper.sendMail(subject, body, this.ASSystem.mailfrom, toMails, this.ASSystem.mailhost, @int, this.ASSystem.mailuser, this.ASSystem.mailpass, this.ASSystem.MailSSL, this.ASSystem.mailreply, out sendOK);
        }
        return sendOK;
    }

    public bool SendSMS(List<string> mobiles, string content)
    {
        if ((this.ASSystem.smsuser == string.Empty) || (this.ASSystem.smspass == string.Empty))
        {
            return false;
        }
        string phone = string.Empty;
        for (int i = 0; i < mobiles.Count; i++)
        {
            phone = phone + "," + mobiles[i];
        }
        if (phone.Length > 0)
        {
            phone = phone.Substring(1);
        }
        return WebSiteHelper.SendSms(this.ASSystem.smsuser, this.ASSystem.smspass, phone, content);
    }

    public void SetCookie(string cookiename, string msg)
    {
        HttpCookie cookie = new HttpCookie("Tuan");
        cookie.Values.Add(cookiename, DESEncrypt.Encrypt(msg, Getkey()));
        HttpContext.Current.Response.AppendCookie(cookie);
    }

    public virtual void SetError(string errtext)
    {
        this.Session["err"] = errtext;
        this.Session["type"] = 1;
    }

    public void SetRefer()
    {
        CookieHelper.SetCookie("refer", base.Request.Url.AbsoluteUri);
    }

    public void SetRefer(string url)
    {
        CookieHelper.SetCookie("refer", url);
    }

    public void SetSuccess(string successtext)
    {
        this.Session["err"] = successtext;
        this.Session["type"] = 2;
    }

    public void SetTitle(string title)
    {
        if (this.ASSystem.Title == string.Empty)
        {
            this.Page.Header.Title = title + "-" + this.ASSystem.sitetitle;
        }
        else
        {
            this.Page.Header.Title = this.ASSystem.Title;
        }
    }

    // Properties
    public Maticsoft.Model.System ASSystem
    {
        get
        {
            if (this._assystem == null)
            {
                this._assystem = new Maticsoft.BLL.System().GetModel(1);
            }
            return this._assystem;
        }
        set
        {
            this._assystem = value;
        }
    }

    public NameValueCollection ASSystemArr
    {
        get
        {
            if (this.ASSystem != null)
            {
                this._assytemarr = Helper.GetObjectProtery(this.ASSystem);
            }
            else
            {
                this._assytemarr = new NameValueCollection();
            }
            return this._assytemarr;
        }
    }

    public Maticsoft.Model.UserInfo AsUser
    {
        get
        {
            if ((this._asuser == null) && this.Page.User.Identity.IsAuthenticated)
            {
                List<Maticsoft.Model.UserInfo> modelList = new Maticsoft.BLL.UserInfo().GetModelList("Username='" + this.Page.User.Identity.Name + "'");
                if (modelList.Count > 0)
                {
                    this._asuser = modelList[0];
                }
            }
            return this._asuser;
        }
    }

    public Maticsoft.Model.UserInfo ASUser
    {
        get
        {
            if ((this.asuser == null) && this.Page.User.Identity.IsAuthenticated)
            {
                List<Maticsoft.Model.UserInfo> modelList = new Maticsoft.BLL.UserInfo().GetModelList("username='" + base.User.Identity.Name + "'");
                if (modelList.Count > 0)
                {
                    this.asuser = modelList[0];
                }
            }
            return this.asuser;
        }
    }

    public NameValueCollection ASUserArr
    {
        get
        {
            if (this.ASUser != null)
            {
                this._ASUserArr = Helper.GetObjectProtery(this.ASUser);
            }
            else
            {
                this._ASUserArr = new NameValueCollection();
            }
            return this._ASUserArr;
        }
    }

    public string city
    {
        get
        {
            string str = "";
            DataSet set = new Maticsoft.BLL.Category().GetList(1, "zone='" + WebSiteHelper.GetCatalogName(CatalogType.city) + "'", "Sort_order desc");
            if ((set.Tables.Count > 0) && (set.Tables[0].Rows.Count > 0))
            {
                str = set.Tables[0].Rows[0]["Name"].ToString();
            }
            return str;
        }
    }

    public DataTable CityList
    {
        get
        {
            if (this._citylist.Rows.Count == 0)
            {
                int count = 0;
                this._citylist = DbHelperSQL.GetDataTableByPager(0x3e8, 1, "Sort_order desc", "Zone='" + WebSiteHelper.GetCatalogName(CatalogType.city) + "'", "category", out count);
            }
            return this._citylist;
        }
    }

    public Maticsoft.Model.Category CurrentCity
    {
        get
        {
            if (this._city == null)
            {
                string cookieValue = CookieHelper.GetCookieValue("cityid");
                if (cookieValue == string.Empty)
                {
                    Maticsoft.BLL.Category category = new Maticsoft.BLL.Category();
                    DataSet set = category.GetList(1, "zone='" + WebSiteHelper.GetCatalogName(CatalogType.city) + "'", "Sort_order desc");
                    if ((set.Tables.Count > 0) && (set.Tables[0].Rows.Count > 0))
                    {
                        List<Maticsoft.Model.Category> list = category.DataTableToList(set.Tables[0]);
                        if (list.Count > 0)
                        {
                            this._city = list[0];
                        }
                    }
                }
                else
                {
                    this._city = new Maticsoft.BLL.Category().GetModel(Helper.GetInt(cookieValue, 0));
                }
            }
            return this._city;
        }
    }

    public Maticsoft.Model.Team CurrentTeam
    {
        get
        {
            if (this._currentteam == null)
            {
                DataTable dt = new DataTable();
                if (this.CurrentCity == null)
                {
                    dt = DbHelperSQL.SelectByFilter("*", "", "", "(select top 1 * from team where Team_type='normal' and Begin_time<='" + DateTime.Now.ToString() + "' and End_time>='" + DateTime.Now.ToString() + "'  order by  sort_order desc,Begin_time desc) as t1");
                }
                else
                {
                    dt = DbHelperSQL.SelectByFilter("*", "", "", string.Concat(new object[] { "(select top 1 * from team where Team_type='normal' and (City_id=", this.CurrentCity.Id, " or city_id=0) and  Begin_time<='", DateTime.Now.ToString(), "' and End_time>='", DateTime.Now.ToString(), "'  order by  sort_order desc ,Begin_time desc ) as t1" }));
                }
                if (dt.Rows.Count > 0)
                {
                    List<Maticsoft.Model.Team> list = new Maticsoft.BLL.Team().DataTableToList(dt);
                    if (list.Count > 0)
                    {
                        this._currentteam = list[0];
                    }
                }
            }
            return this._currentteam;
        }
    }

    public string Domain
    {
        get
        {
            Regex regex = new Regex("http://(.+?)/");
            return regex.Replace(regex.Match(base.Request.Url.AbsoluteUri).Value, "$1");
        }
    }

    public string ename
    {
        get
        {
            string str = "";
            DataSet set = new Category().GetList(1, "zone='" + WebSiteHelper.GetCatalogName(CatalogType.city) + "'", "Sort_order desc");
            if ((set.Tables.Count > 0) && (set.Tables[0].Rows.Count > 0))
            {
                str = set.Tables[0].Rows[0]["ename"].ToString();
            }
            return str;
        }
    }

    public bool IsLogin
    {
        get
        {
            bool flag = false;
            if (this.Page.User.Identity.IsAuthenticated)
            {
                flag = true;
            }
            return flag;
        }
    }

    public bool IsManage
    {
        get
        {
            if (!this._ismanager.HasValue)
            {
                if ((this.AsUser != null) && ((this.AsUser.Manager.ToUpper() == "Y") || (this.ASUser.Id == 1)))
                {
                    this._ismanager = true;
                }
                if (!this._ismanager.HasValue)
                {
                    this._ismanager = false;
                }
            }
            return this._ismanager.Value;
        }
    }

    public bool IsPartner
    {
        get
        {
            if (!this.ispartner)
            {
                if (this.GetCookie("partnerid") != string.Empty)
                {
                    this.ispartner = true;
                }
                else
                {
                    this.ispartner = false;
                }
            }
            return this.ispartner;
        }
    }

    public bool IsSupper
    {
        get
        {
            return (Helper.GetInt(this.GetCookie("admin"), 0) == 1);
        }
    }

    public string UserName
    {
        get
        {
            string name = string.Empty;
            if (this.Page.User.Identity.IsAuthenticated)
            {
                name = this.Page.User.Identity.Name;
            }
            return name;
        }
    }

    public string WebRoot
    {
        get
        {
            return this.Page.ResolveUrl("~/");
        }
    }

    public string WWWprefix
    {
        get
        {
            Regex regex = new Regex("http://(.+?)/");
            return regex.Match(base.Request.Url.AbsoluteUri).Value;
        }
    }
}


